/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef NODE_CRYPTO_HMAC_H_
#define NODE_CRYPTO_HMAC_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <cstddef>
#include <cstdint>
#include <openssl/hmac.h>
#include <openssl/sha.h>
#include "node/node.h"

#define SEED_KEY_SIZE 16

namespace node {
    namespace crypto {
        class BigNumber;

        class HmacHash
        {
        public:
            HmacHash(void);
            ~HmacHash(void);

            void updateBigNumber(::node::crypto::BigNumber* bn);
            void updateData(const ::std::uint8_t* data, int size);
            void initialize();
            void finalize();
            ::std::uint8_t* digest() { return digest_; }
            int length() { return SHA_DIGEST_LENGTH; }
        private:
            HMAC_CTX ctx_;
            ::std::uint8_t key_[SEED_KEY_SIZE];
            ::std::uint8_t digest_[SHA_DIGEST_LENGTH]; 

            DISALLOW_COPY_AND_ASSIGN(HmacHash);
        };

    }
}

#endif // NODE_CRYPTO_HMAC_H_
